import { get, post } from "@/utils/request"

export default {
    namespaced: true,
    state: {
        articles: [],
        article: []
    },
    mutations: {
        refreshFinaArticleById(state,data) {
            state.article = data
        },
        refreshQueryArticles(state,data) {
            state.articles = data
        }
    },
    actions: {
        // 根据id查询文章
        async finaArticleById({commit},id) {
            let res = await get("/article/findById",{id});
            commit("refreshFinaArticleById",res.data)
        },
        // 保存
        async saveOrUpdateArticle({dispatch},params) {
            let res = await post("/article/saveOrUpdate",params);
            return res
        },
        // 删除
        async deleteArticle({dispatch},id) {
            let res = await get("/article/deleteById",{id});
            return res; 
        },
        // 分页查询
        async queryArticles({commit},params) {
            let res = await get("/article/pageQuery",params);
            commit('refreshQueryArticles',res.data);
            return res
        }
    }
}